<?php
class Admincp_Model_Block extends Zend_Db_Table_Abstract
{
    protected $_db;

    public function __construct()
    {
        $this->_db = Zend_Registry::get('db');
    }

    public function listBlock($locale)
    {
        $sql = $this->_db->select()
                        ->from('block AS b', array('b.id','b.block'))
                        ->join('block_language AS bl', 'b.id = bl.block_id', array('bl.name'))
                        ->join('language AS l', 'bl.language_id = l.id', null)
                        ->where('l.locale = ?', $locale)
                        ->order('b.id ASC');
        return $sql;
    }

    public function getBlockById($id)
    {
        $sql = $this->_db->select()
                        ->from('block_language AS bl', array('name','description'))
                        ->join('language AS l', 'bl.language_id = l.id', array('locale'))
                        ->where('bl.block_id = ?', $id);
        $result = $this->_db->fetchAll($sql);
        return $result;
    }

    public function updateBlockLanguage($data,$id)
    {
        $where = 'block_id = '.$id.' AND language_id = '.$data['language_id'];
        $this->_db->update('block_language', $data, $where);
    }
}
